﻿using CurveFitting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ChartControlsReleaseTest
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class KzCurve : Window
    {
        public KzCurve()
        {
            InitializeComponent();
            myLineChart.ChartPanel.AddYAxis("Pfe(W)", Brushes.Green, 1000, 0);
            myLineChart.ChartPanel.AddYAxis("Pcon(W)", Brushes.Green, 1000, 0);
            myLineChart.ChartPanel.AddYAxis("Po(W)", Brushes.Blue, 1000, 0);
            //myLineChart.ChartPanel. = 5;
            AddData();
        }

        private void AddData()
        {
            double[] Uo_Un = { 430.3 / 380, 415.8 / 380, 380.7 / 380, 334.2 / 380, 267.7 / 380, 206.6 / 380, 186.5 / 380, 166.9 / 380, 139.9 / 380, 101.1 / 380 };
            double[] Po = { 837.3, 697.1, 484, 337.35, 214.65, 135.26, 115.18, 96.76, 75.58, 49.44 };
            double[] Io = { 16.203, 14.262, 10.853, 8.228, 6.007, 4.437, 3.961, 3.51, 2.914, 2.111 };
            double[] Pfe = { 615.24, 519.74, 371.36, 262.57, 163.79, 96.78, 79.72, 63.84, 45.54, 22.44 };
            double[] Uo_Un2 = { Math.Pow(206.6 / 380, 2), Math.Pow(186.5 / 380, 2), Math.Pow(166.9 / 380, 2), Math.Pow(139.9 / 380, 2), Math.Pow(101.1 / 380, 2) };
            double[] Pcon = { 120.43, 103.37, 87.49, 69.19, 46.90 };

            LineCharts.FittingCurve Po_PU = new LineCharts.FittingCurve();
            Po_PU.LineColor = myLineChart.ChartPanel.YAxises["Po(W)"].AxisColor;
            Po_PU.XDrawStart = 0.2;
            Po_PU.XDrawEnd = 1.25;
            Po_PU.RateXValue = 1;
            Po_PU.FitM = 8;
            Po_PU.FittingMode = LineCharts.FittingCurve.FittingModeEnum.PolynomialFit;
            Po_PU.LineThickness = 2;
            Po_PU.SeriesName = "Po=f(Uo/Un)";
            Po_PU.Symbols.SymbolType = LineCharts.Symbols.SymbolTypeEnum.Diamond;
            Po_PU.Symbols.SymbolSize = 10;
            Po_PU.Symbols.FillColor = Brushes.Transparent;
            Po_PU.Symbols.BorderColor = Po_PU.LineColor;
            for (int i = 0; i < Uo_Un.Length; i++)
            {
                Po_PU.RawData.Add(Uo_Un[i], Po[i]);
            }
            myLineChart.SeriesCollection.AddRawData(Po_PU, "Po(W)");

            LineCharts.FittingCurve Io_PU = new LineCharts.FittingCurve();
            Io_PU.LineColor = myLineChart.ChartPanel.YAxises["Io(A)"].AxisColor;
            Io_PU.XDrawStart = 0.2;
            Io_PU.XDrawEnd = 1.25;
            Io_PU.RateXValue = 1;
            Io_PU.FitM = 8;
            Io_PU.LinePattern = LineCharts.LinePatternEnum.Dash;
            Io_PU.FittingMode = LineCharts.FittingCurve.FittingModeEnum.PolynomialFit;
            Io_PU.LineThickness = 2;
            Io_PU.SeriesName = "Io=f(Uo/Un)";
            Io_PU.Symbols.SymbolType = LineCharts.Symbols.SymbolTypeEnum.InvertedTriangle;
            Io_PU.Symbols.SymbolSize = 10;
            Io_PU.Symbols.FillColor = Brushes.Transparent;
            Io_PU.Symbols.BorderColor = Io_PU.LineColor;
            for (int i = 0; i < Uo_Un.Length; i++)
            {
                Io_PU.RawData.Add(Uo_Un[i], Io[i]);
            }
            myLineChart.SeriesCollection.AddRawData(Io_PU, "Io(A)");

            LineCharts.FittingCurve Pfe_PU = new LineCharts.FittingCurve();
            Pfe_PU.LineColor = myLineChart.ChartPanel.YAxises["Pfe(W)"].AxisColor;
            Pfe_PU.XDrawStart = 0.2;
            Pfe_PU.XDrawEnd = 1.25;
            Pfe_PU.RateXValue = 1;
            Pfe_PU.FitM = 8;
            Pfe_PU.LinePattern = LineCharts.LinePatternEnum.DashDot;
            Pfe_PU.FittingMode = LineCharts.FittingCurve.FittingModeEnum.PolynomialFit;
            Pfe_PU.LineThickness = 2;
            Pfe_PU.SeriesName = "Pfe=f(Uo/Un)";
            Pfe_PU.Symbols.SymbolType = LineCharts.Symbols.SymbolTypeEnum.OpenTriangle;
            Pfe_PU.Symbols.SymbolSize = 10;
            Pfe_PU.Symbols.FillColor = Brushes.Transparent;
            Pfe_PU.Symbols.BorderColor = Pfe_PU.LineColor;
            for (int i = 0; i < Uo_Un.Length; i++)
            {
                Pfe_PU.RawData.Add(Uo_Un[i], Pfe[i]);
            }
            myLineChart.SeriesCollection.AddRawData(Pfe_PU, "Pfe(W)");

            LineCharts.FittingCurve Pcon_PU2 = new LineCharts.FittingCurve();
            Pcon_PU2.LineColor = myLineChart.ChartPanel.YAxises["Pcon(W)"].AxisColor;
            Pcon_PU2.XDrawStart = 0;
            Pcon_PU2.XDrawEnd = 0.35;
            Pcon_PU2.LinePattern = LineCharts.LinePatternEnum.Dot;
            Pcon_PU2.FittingMode = LineCharts.FittingCurve.FittingModeEnum.StraightLineFit;
            Pcon_PU2.LineThickness = 2;
            Pcon_PU2.SeriesName = "Pcon=f(Uo/Un)^2";
            Pcon_PU2.Symbols.SymbolType = LineCharts.Symbols.SymbolTypeEnum.Circle;
            Pcon_PU2.Symbols.SymbolSize = 10;
            Pcon_PU2.Symbols.FillColor = Brushes.Transparent;
            Pcon_PU2.Symbols.BorderColor = Pcon_PU2.LineColor;
            for (int i = 0; i < Uo_Un2.Length; i++)
            {
                Pcon_PU2.RawData.Add(Uo_Un2[i], Pcon[i]);
            }
            myLineChart.SeriesCollection.AddRawData(Pcon_PU2, "Pcon(W)");
        }
    }
}
